// 微赞云 API

const install = (Vue, vm) => {
	Vue.prototype.$u.http.setConfig({
		baseUrl: 'https://openapi.vzan.com/api/v1'
	});
	// 请求拦截
	Vue.prototype.$u.http.interceptor.request = (config) => {
		let token = uni.getStorageSync('token');
		if (token) {
			config.header.Authorization = `Bearer ${token}`;
		}
		return config;
	}
	// 响应拦截
	Vue.prototype.$u.http.interceptor.response = (res) => {
		if (res.code == 0) {
			return res;
		} else if (res.code == -1) {
			vm.$getToken();
		} else if(res.code == -3) {
			// 无鉴权参数
			location.reload();
		}
	}
}

export default install